package DomainLayer;
import java.util.ArrayList;

public class LoanCollection
{
    private ArrayList<Loan> list;
    private static LoanCollection instance;

    private LoanCollection()
    {
        list=new ArrayList<Loan>();
    }
    
    //@return only one object of class LoanCollection.
    public static LoanCollection getInstance()
    {
        if(instance==null)
        instance=new LoanCollection();
        return instance;
    }

    public void addLoan(Loan loan)
    {
        list.add(loan);
    }
    
    public Loan searchLoan(int id)
    {
        for(Loan loan: list)
        {
            if(loan.getID()==id)
            {
                return loan;
            }
        }
        return null;
    }
    
    /**
     * Creates new loan and adds it to loan collection.
     * 
     * @param tools a list of tools leased out.
     * @param customer a customer who rented tools.
     * @param assistant an employee who leased ou the tools.
     * @param year, month, day - date when tools were leased out.
     */
    public int createLoan( ArrayList<Tool> tools, Customer customer, Assistant assistant,int year, int month, int day)
    {
        int id=list.size()+1;
        Loan loan= new Loan(id, tools, customer, assistant,year,month,day);
        addLoan(loan);
        return id;
    }
    
    public void deleteLoan(int id)
    {
        list.remove(searchLoan(id));
    }
    
    
    public String printLoan(int id)
    {
        return searchLoan(id).toString();
    }  
}